<template>
    <div>
chengg
<h2>管理员登录</h2>
<table class="table table-bordered">
<tr>
    <td align="right">账号</td>
    <td><input type="text" v-model="state.username" /></td>
</tr>
<tr>
    <td align="right">密码</td>
    <td><input type="password" v-model="state.password" /></td>
</tr>
<tr>
    <td align="right"></td>
    <td><input type="button" value="登录" @click="login" /></td>
</tr>
</table>
    </div>
</template>

<script setup lang="ts">
import { reactive,toRefs } from 'vue';
import { useRouter,useRoute } from 'vue-router';
import axios from 'axios';
const router=useRouter();
let data=reactive({
    state:{
        username:'',
        password:''
    }
})
let{state}=toRefs(data)

const login=()=>{

if(state.value.username==""){
    alert("账号不能为空")
    return;
}
if(state.value.password==""){
    alert("密码不能为空")
    return;
}
    let obj={
        username:state.value.username,
        password:state.value.password,
    }
    axios({
        url:'/api/Admin/Login',
        method:'post',
        params:obj
    })
    .then(res=>{
        console.log(res)
        if(res.data==1){
            alert("登录成功")
            router.push("/DisAdd")
        }
        else{
            alert("登录失败")
            return;
        }
    })
    .catch(err=>{
        console.log(err)
    })
}

</script>

<style scoped>

</style>